using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using MM.Entities;

namespace MM.Business
{
    class clsIMPA_WORD_IMAGE
    {
        public clsIMPA_WORD_IMAGE(string sConn)
        {
            SqlHelper.ConnectionString = sConn;
        }
        public List<IMPA_WORD_IMAGE> DataTableToLstObj(DataTable dt)
        {
            IMPA_WORD_IMAGE wordImageDTO;
            List<IMPA_WORD_IMAGE> lstWordImageDTO = new List<IMPA_WORD_IMAGE>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                wordImageDTO = new IMPA_WORD_IMAGE();
                try
                {
                    wordImageDTO._number = int.Parse(dt.Rows[i]["Number"].ToString());
                }
                catch (Exception ex)
                {
                }
                try
                {
                    wordImageDTO._subSlno = int.Parse(dt.Rows[i]["SubSlno"].ToString());
                }
                catch (Exception ex)
                {
                }
                try
                {
                    wordImageDTO._l2Code = int.Parse(dt.Rows[i]["L2Code"].ToString());
                }
                catch (Exception ex)
                {
                }
                try
                {
                    wordImageDTO._l3Code = int.Parse(dt.Rows[i]["L3Code"].ToString());
                }
                catch (Exception ex)
                {
                }
                try
                {
                    wordImageDTO._jpgName = dt.Rows[i]["JpgName"].ToString();
                }
                catch (Exception ex)
                {
                }
                lstWordImageDTO.Add(wordImageDTO);
            }
            return lstWordImageDTO;
        }
        public IMPA_WORD_IMAGE DataTableToObj(DataTable dt)
        {
            IMPA_WORD_IMAGE wordImageDTO;
            wordImageDTO = new IMPA_WORD_IMAGE();
            try
            {
                wordImageDTO._number = int.Parse(dt.Rows[0]["Number"].ToString());
            }
            catch (Exception ex)
            {
            }
            try
            {
                wordImageDTO._subSlno = int.Parse(dt.Rows[0]["SubSlno"].ToString());
            }
            catch (Exception ex)
            {
            }
            try
            {
                wordImageDTO._l2Code = int.Parse(dt.Rows[0]["L2Code"].ToString());
            }
            catch (Exception ex)
            {
            }
            try
            {
                wordImageDTO._l3Code = int.Parse(dt.Rows[0]["L3Code"].ToString());
            }
            catch (Exception ex)
            {
            }
            try
            {
                wordImageDTO._jpgName = dt.Rows[0]["JpgName"].ToString();
            }
            catch (Exception ex)
            {
            }

            return wordImageDTO;
        }
        public List<IMPA_WORD_IMAGE> LoadImpaWordImageByL2(int l2)
        {
            DataTable dt = new DataTable();
            List<IMPA_WORD_IMAGE> lstWImageDTO = new List<IMPA_WORD_IMAGE>();
            try
            {
                SqlHelper.OpenConnection();
                string spName = "usp_SelectIMPA_WORD_IMAGE_ByL2";
                SqlParameter[] par = new SqlParameter[1];
                par[0] = new SqlParameter("@l2", l2);
                dt = SqlHelper.ExecuteToDataTable(spName, par);
                lstWImageDTO = DataTableToLstObj(dt);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (!SqlHelper.IsHaveTran())
                    SqlHelper.CloseConnection();
            }
            return lstWImageDTO;
        }
        public List<IMPA_WORD_IMAGE> LoadImpaWordImageByL2AndL3(int l2, int l3)
        {
            DataTable dt = new DataTable();
            List<IMPA_WORD_IMAGE> lstWImageDTO = new List<IMPA_WORD_IMAGE>();
            try
            {
                SqlHelper.OpenConnection();
                string spName = "usp_SelectIMPA_WORD_IMAGE_ByL2&L3";
                SqlParameter[] par = new SqlParameter[2];
                par[0] = new SqlParameter("@l2", l2);
                par[1] = new SqlParameter("@l3", l3);
                dt = SqlHelper.ExecuteToDataTable(spName, par);
                lstWImageDTO = DataTableToLstObj(dt);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (!SqlHelper.IsHaveTran())
                    SqlHelper.CloseConnection();
            }
            return lstWImageDTO;
        }
        public List<IMPA_WORD_IMAGE> LoadImpaWordImageByCode(string code)
        {
            DataTable dt = new DataTable();
            List<IMPA_WORD_IMAGE> lstWImageDTO = new List<IMPA_WORD_IMAGE>();
            try
            {
                SqlHelper.OpenConnection();
                string spName = "usp_SelectIMPA_WORD_IMAGE_ByCode";
                SqlParameter[] par = new SqlParameter[1];
                par[0] = new SqlParameter("@Code", code);
                dt = SqlHelper.ExecuteToDataTable(spName, par);
                lstWImageDTO = DataTableToLstObj(dt);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (!SqlHelper.IsHaveTran())
                    SqlHelper.CloseConnection();
            }
            return lstWImageDTO;
        }
        public List<IMPA_WORD_IMAGE> LoadImpaWordImageByCodeAndL3Is0(string code)
        {
            DataTable dt = new DataTable();
            List<IMPA_WORD_IMAGE> lstWImageDTO = new List<IMPA_WORD_IMAGE>();
            try
            {
                SqlHelper.OpenConnection();
                string spName = "usp_SelectIMPA_WORD_IMAGE_ByCodeAndL3Is0";
                SqlParameter[] par = new SqlParameter[1];
                par[0] = new SqlParameter("@Code", code);
                dt = SqlHelper.ExecuteToDataTable(spName, par);
                lstWImageDTO = DataTableToLstObj(dt);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (!SqlHelper.IsHaveTran())
                    SqlHelper.CloseConnection();
            }
            return lstWImageDTO;
        }
    }
}
